home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: const pointer confusion...
- Date: 26 Mar 1996 18:56:14 -0600
- Organization: TU Wien
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4ja3ne$p6j@solutions.solon.com>
- References: <4j06gm$7oa@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- Reed R. Mangino <mangino@planet.net> writes:
-
- |> 1) const int *p = 10;
-
- A point not mentioned by earlier correct follow-ups is that
- 10 is being assigned to p here, and not to *p. Assigning 10 to p
- is suspicious. If you want to assign 10 to *p, you must make
- p point to an integer first. Of course, you then can't, because *p is const.
- One way out of this problem is
-
- const int secret = 10, *p = &secret;
-
- The rule I use for const is that const binds to the left, unless it can't,
- then it binds to the right. *const *p is a pointer to a constant
- pointer.
-
- Konrad Schwarz
-